<template>
  <div>
    <el-input v-model="searchText" placeholder="搜索文档"></el-input>
    <el-table :data="filteredDocs">
      <el-table-column prop="name" label="文件名"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button @click="openDoc(scope.row)">打开</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button type="primary" @click="showAddDialog=true">添加文档</el-button>
    
    <add-doc :visible.sync="showAddDialog"></add-doc>
  </div>
</template>

<script>
import AddDoc from '../components/AddDoc.vue'
import Fuse from 'fuse.js'

export default {
  components: { AddDoc },
  data() {
    return {
      docs: JSON.parse(localStorage.getItem('docs')) || [],
      searchText: '',
      showAddDialog: false
    }
  },
  computed: {
    filteredDocs() {
      if (!this.searchText) return this.docs
      const fuse = new Fuse(this.docs, { keys: ['name'] })
      return fuse.search(this.searchText).map(i => i.item)
    }
  },
  methods: {
    openDoc(doc) {
      // 实际项目中这里调用文件系统API
      alert(`打开文件: ${doc.name}`)
    }
  }
}
</script>